import random
import pandas as pd

# 定义从景点描述中提取关键信息的函数
def extract_key_info(text):
    key_info = []
    keywords = ["历史", "古迹", "自然", "亲子", "文化", "探险", "海洋", "科普", "户外",
                "登山", "滑雪", "拍照", "美食", "绘画", "音乐", "读书", "购物", "宠物",
                "动物", "昆虫", "大海", "海滨", "古镇", "古建筑", "乐园", "游乐场", "园林",
                "景色"]
    for keyword in keywords:
        if keyword in text:
            key_info.append(keyword)
    return key_info

# 定义用户画像生成函数，根据景点关键信息生成爱好
def generate_user_profile(key_info, default_hobby):
    if "历史" in key_info or "古迹" in key_info or "文化" in key_info:
        hobbies = ['历史研究', '古代文物鉴赏', '历史文化书籍阅读', '古建筑绘画']
    elif "自然" in key_info or "户外" in key_info or "登山" in key_info or "滑雪" in key_info:
        hobbies = ['自然风光摄影', '徒步旅行', '登山运动', '滑雪体验', '自然写生']
    elif "亲子" in key_info:
        hobbies = ['亲子手工制作', '亲子户外探险', '亲子摄影']
    elif "乐园"  in key_info or "游乐场" in key_info:
        hobbies = ['去游乐园','去游乐场']
    elif "海洋" in key_info or "大海" in key_info or "海滨" in key_info:
        hobbies = ['看海', '海边玩']
    elif "科普" in key_info  or "动物" in key_info:
        hobbies = ['看动物', '动物科普', '逛动物园']
    elif "昆虫" in key_info:
        hobbies =['昆虫研究','观察昆虫','养小蚂蚁','养昆虫']
    elif "美食" in key_info:
        hobbies = ['特色美食品尝', '美食烹饪学习', '美食摄影']
    elif "绘画" in key_info:
        hobbies = ['风景绘画', '人物绘画', '写生创作']
    elif "音乐" in key_info:
        hobbies = ['乐器演奏', '音乐创作', '音乐欣赏']
    elif "读书" in key_info:
        hobbies = ['文学书籍阅读', '历史书籍阅读', '科普书籍阅读']
    elif "购物" in key_info:
        hobbies = ['特色商品购物', '古董购物', '时尚购物']
    elif "宠物" in key_info:
        hobbies = ['宠物饲养', '宠物摄影', '宠物知识学习','养宠物']
    elif "古镇" in key_info or "古建筑" in key_info or "园林":
        hobbies = ['古建筑研究', '逛历史文化街区', '游玩古镇']
    elif "景色" in key_info:
        hobbies = ['风景摄影', '景色拍摄', '自然风光摄影', '旅行摄影']
    else:
        # 如果没有匹配的关键词，使用提供的默认爱好（景点类型）
        return f"爱好是{default_hobby}"

    hobby = random.choice(hobbies)
    return f"爱好是{hobby}"

# 加载景点数据
df = pd.read_csv('./attraction_data.csv')

# 生成用户画像和景点偏好数据
user_profiles = []
for index, row in df.iterrows():
    key_info = extract_key_info(row['text'])
    # 将景点类型作为默认爱好传入
    user_profile = generate_user_profile(key_info, row['label'])
    user_profiles.append(user_profile)

# 将用户画像添加到新的DataFrame中
new_df = pd.DataFrame({
    'hobby_label': user_profiles,
    'attraction_text': df['text'],
    'attraction_label': df['label']
})

# 保存为csv文件
file_path = './user_profile_attraction_preference.csv'
new_df.to_csv(file_path, index=False)
